name: Build

on:
  push:
    branches: [ '*' ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Install Arduino CLI
      run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
    - name: Build firmware
      run: make

  build_macos:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v3
    - name: Install Arduino CLI
      run: brew install arduino-cli
    - name: Build firmware
      run: make

  build_windows:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v3
    - name: Install Arduino CLI
      run: choco install arduino-cli
    - name: Install Make
      run: choco install make
    - name: Build firmware
      run: make

  build_simulator:
    runs-on: ubuntu-latest
    steps:
    - name: Install Arduino CLI
      uses: arduino/setup-arduino-cli@v1.1.1
    - uses: actions/checkout@v3
    - name: Install Gazebo
      run: curl -sSL http://get.gazebosim.org | sh
    - name: Install SDL2
      run: sudo apt-get install libsdl2-dev
    - name: Build simulator
      run: make build_simulator
    - uses: actions/upload-artifact@v3
      with:
        name: gazebo-plugin-binary
        path: gazebo/build/*.so
        retention-days: 1

  build_simulator_macos:
    runs-on: macos-latest
    steps:
    - name: Install Arduino CLI
      run: brew install arduino-cli
    - uses: actions/checkout@v3
    - name: Clean up python binaries # Workaround for https://github.com/actions/setup-python/issues/577
      run: |
        rm -f /usr/local/bin/2to3*
        rm -f /usr/local/bin/idle3*
        rm -f /usr/local/bin/pydoc3*
        rm -f /usr/local/bin/python3*
        rm -f /usr/local/bin/python3*-config
    - name: Install Gazebo
      run: brew update && brew tap osrf/simulation && brew install gazebo11
    - name: Install SDL2
      run: brew install sdl2
    - name: Build simulator
      run: make build_simulator
